package com.rykj.ruiyan_ptz.wiget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.os.Build
import android.text.Editable
import android.text.TextPaint
import android.text.TextUtils
import android.util.AttributeSet
import android.view.View
import android.widget.GridLayout
import android.widget.LinearLayout
import androidx.annotation.RequiresApi
import com.rykj.ruiyan_ptz.Define
import com.rykj.ruiyan_ptz.R
import com.rykj.ruiyan_ptz.control.UDPManager
import com.rykj.socket_lib.SocketLib
import kotlinx.android.synthetic.main.ptz_control_widget.view.*

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
class PTZControlWidget
@JvmOverloads
constructor(contex: Context, attrs: AttributeSet, defStyle: Int = 0, defStyleRes: Int = 0) :
    GridLayout(contex, attrs, defStyle, defStyleRes) {
    private val define: Define = Define()

    init {
        View.inflate(context, R.layout.ptz_control_widget, this)
        init()
    }

    fun init() {
        ptz_up.setOnClickListener {
            println("ptz_up")
            UDPManager.get().PtzMove(define.ptzType_Yaw, define.PTZ_UP, 500, 255);
        }
        ptz_down.setOnClickListener {
            println("ptz_down")
            UDPManager.get().PtzMove(define.ptzType_Yaw, define.PTZ_DOWN, 500, 255);
        }
        ptz_base.setOnClickListener {
            println("ptz_base")
            UDPManager.get().PtzMove(define.ptzType_Zero, define.PTZ_UP, 500, 255);
        }
        ptz_left.setOnClickListener {
            println("ptz_left")
            UDPManager.get().PtzMove(define.ptzType_Pitch, define.PTZ_LEFT, 500, 255);
        }
        ptz_right.setOnClickListener {
            println("ptz_right")
            UDPManager.get().PtzMove(define.ptzType_Pitch, define.PTZ_RIGHT, 500, 255);
        }
    }
}